<?php

class ListasdesplegablesController extends GxController {

public function filters() {
	return array(
			'accessControl', 
			);
}


public function accessRules() {
	return array(
			array('allow',
				'actions'=>array('index','view'),
				'users'=>array('*'),
				),
			array('allow', 
				'actions'=>array('minicreate', 'create','update'),
				'users'=>array('@'),
				),
			array('allow', 
				'actions'=>array('admin','delete'),
				'users'=>array('admin'),
				),
			array('deny', 
				'users'=>array('*'),
				),
			);
}

	public function actionView($id) {
                $this->layout = '//layouts/column3';
		$this->render('view', array(
			'model' => $this->loadModel($id, 'Listasdesplegables'),
		));
	}

	public function actionCreate($campo="") {
                $this->layout = '//layouts/column3';
		$model = new Listasdesplegables;
                
                if(is_numeric($campo)){
                      $model->CMP_ID=$campo;
                      $model->ORDEN = Yii::app()->db->createCommand("SELECT MAX(ORDEN) + 1 FROM LISTASDESPLEGABLES WHERE CMP_ID=$campo")->queryScalar();
                }
                
		$this->performAjaxValidation($model, 'listasdesplegables-form');
                Controller::registrar_scrips();
                Controller::registrar_scrips_jquery();
		if (isset($_POST['Listasdesplegables'])) {
			$model->setAttributes($_POST['Listasdesplegables']);

			if ($model->save()) {
				if (Yii::app()->getRequest()->getIsAjaxRequest())
					Yii::app()->end();
				else
					$this->redirect(array('view', 'id' => $model->LISTID));
			}
		}

		$this->render('create', array( 'model' => $model));
	}

	public function actionUpdate($id) {
                $this->layout = '//layouts/column3';
		$model = $this->loadModel($id, 'Listasdesplegables');
                
		$this->performAjaxValidation($model, 'listasdesplegables-form');
                Controller::registrar_scrips();
                Controller::registrar_scrips_jquery();
		if (isset($_POST['Listasdesplegables'])) {
			$model->setAttributes($_POST['Listasdesplegables']);

			if ($model->save()) {
				$this->redirect(array('view', 'id' => $model->LISTID));
			}
		}

		$this->render('update', array(
				'model' => $model,
				));
	}

	public function actionDelete($id,$campo="") {
		if (Yii::app()->getRequest()->getIsPostRequest()) {
			$this->loadModel($id, 'Listasdesplegables')->delete();

			if (!Yii::app()->getRequest()->getIsAjaxRequest())
				$this->redirect(array('admin', 'campo'=>$campo));
		} else
			throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
	}

	public function actionIndex($campo="") {
                $condicion="";
                //$campo=424;
                $this->layout = '//layouts/column3';
                if(is_numeric($campo))
                    $condicion= "CMP_ID=$campo";
		$dataProvider = new CActiveDataProvider('Listasdesplegables', array('criteria'=>array(
                    'condition'=>$condicion,
                    'order'=>'ORDEN DESC',
                    'params'=> $campo),
                ));
		$this->render('index', array(
			'dataProvider' => $dataProvider,
		));
	}

	public function actionAdmin($campo="") {
                //$campo=424;
                $this->layout = '//layouts/column3';
		$model = new Listasdesplegables('search');
		$model->unsetAttributes();
                
                if (is_numeric($campo))
                    $model->CMP_ID=$campo;
                
                if (isset($_GET['Listasdesplegables']))
			$model->setAttributes($_GET['Listasdesplegables']);
                 
		$this->render('admin', array(
			'model' => $model,
		));
	}
       
}